package com.dr.controller.admin;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dr.entity.User;
import com.dr.service.UserService;
import com.dr.util.LayUiResult;


@Controller
@RequestMapping("/admin/")
public class UserContorller{
	//注入service
	@Autowired
	private UserService userService;
	/**
	 * 全查
	 * @param p
	 * @return	以Map的方式返回查询到的数据和行数
	 */
	@RequestMapping(value = "/findUser.do",method = RequestMethod.GET)
	@ResponseBody//转为json格式数据
	public Map<String, Object> findProduct(User u) {
		//调用service
		List<User> list = userService.AllUser(u);
		int count = userService.getCount(u);
		//返回结果都是以Map的方式返会给Layui所以返回值都是Map
		return LayUiResult.toClient("0", "succsee" , count, list);
	}
	
	
	@RequestMapping(value = "/updateUser.do",method = RequestMethod.POST)
	@ResponseBody 
	public Map<String, Object> updateProduct(int id ,String valid){ 
	  int isLock = valid.equals("on") ? 1 :0;
	  //调用service 
	  int res = userService.updateUser(id,isLock); 
	  //返回结果 
	  return res>0 ? LayUiResult.toClient("0", "修改成功") :
	  LayUiResult.toClient("1", "修改失败"); 
	  }

}
